package com.Dialogs;


import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import com.Adapters.PictureListAdapter;
import com.Adapters.Items.ItemPostPicture;
import com.Adapters.Items.ItemProfile;
import com.Data.Albums;
import com.Managers.FragmentManagerClass;
import com.shareup.R;


public class DialogPicture extends AlertDialog {

    private String ITEM_DELETE;

    private String ITEM_COVER;

    private String ITEM_COVER_ALBUM;

    private String ITEM_PROFILE;

    @Override
    public void setTitle(CharSequence title) {

    }

    private ItemPostPicture ItemPicture;

    private final ListView itemlist;

    private final OnItemClickListener OnOption = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adat, View v, int position, long arg3) {

            String menu = ((TextView) v.findViewById(R.id.text_comment)).getText().toString();

            if (menu.equals(ITEM_PROFILE))
                ItemPicture.setCurrentAsProfile();
            else
                if (menu.equals(ITEM_COVER))
                    ItemPicture.setCurrentAsCover();
                else
                    if (menu.equals(ITEM_COVER_ALBUM))
                        ItemPicture.setCurrentAsAlbumCover();
                    else
                        if (menu.equals(ITEM_DELETE))
                            ItemPicture.delete();

            dismiss();
        }
    };

    private final View view;

    public DialogPicture(Context context, boolean isOwner,
                ItemPostPicture itempic) {

        super(context);

        this.ItemPicture = itempic;
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.dialog_action_list, null);
        itemlist = (ListView) view.findViewById(R.id.item_list);
        this.setView(view);

        String[] list = context.getResources().getStringArray(R.array.picture_menu_owner);
        PictureListAdapter adapter = new PictureListAdapter(context, R.layout.option_picture_text, R.id.text_comment);
        //
        ITEM_PROFILE = list[0];
        ITEM_COVER = list[1];
        ITEM_COVER_ALBUM = list[2];
        ITEM_DELETE = list[3];

        adapter.add(new ItemProfile(ITEM_PROFILE, R.drawable.profile_picture_icon, 0, false));
        adapter.add(new ItemProfile(ITEM_COVER, R.drawable.sprofile_icon_menu, 0, false));

        if (FragmentManagerClass.aAlbumDetail != null) {
            Albums al = FragmentManagerClass.aAlbumDetail.album;
            Albums pt = itempic.getPicture().getAlbum();
            if (pt != null && al != null && pt.getID() == al.getID()) {
                adapter.add(new ItemProfile(ITEM_COVER_ALBUM, R.drawable.album_normal, 0, false));

            }

        }

        if (isOwner) {
            adapter.add(new ItemProfile(ITEM_DELETE, R.drawable.delete_normal, 0, false));

        }

        itemlist.setAdapter(adapter);
        itemlist.setOnItemClickListener(OnOption);
    }

}
